﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2022   保留所有权利。
 * CLR版本：4.0.30319.42000
 * 机器名称：DESKTOP-UL84BU5
 * 公司名称：
 * 命名空间：KingerRobot.WanliWMS.SpiService.Services.Mateiral
 * 唯一标识：2c2a7fd8-7693-4437-944e-e9bac5efe4c1
 * 文件名：MaterialManageImpl
 * 当前用户域：DESKTOP-UL84BU5
 * 
 * 创建者：zzl
 * 电子邮箱：1003590782@qq.com
 * 创建时间：2022/7/4 10:54:33
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using KingerRobot.MexicoSailunWMS.Spi;
using KingerRobot.MexicoSailunWMS.SpiService.Services;
using System;

namespace KingerRobot.MexicoSailunWMS.SpiService;
//WMS.Material
public class BMaterialManageImpl : IMaterialManageService
{
    private readonly static IProdMaterial _ProdMaterial = new BProdMaterial();
    public List<MaterialBean> GetMaterialBeans(MaterialPara materialPara)
    {
        var result = _ProdMaterial.GetAllMaterialList();
        if (!string.IsNullOrWhiteSpace(materialPara?.Spec))
        {
            result = result.Where(t => t.Spec.Contains(materialPara.Spec)).ToList();
        }
        if (!string.IsNullOrWhiteSpace(materialPara?.MaterialCode))
        {
            result = result.Where(t => t.MaterialCode.Contains(materialPara.MaterialCode)).ToList();
        }
        if (!string.IsNullOrWhiteSpace(materialPara?.MaterialName))
        {
            result = result.Where(t => t.MaterialName.Contains(materialPara.MaterialName)).ToList();
        }
        if (materialPara.UseFlag != null || materialPara.UseFlag >= 0)
        {
            result = result.Where(t => t.UseFlag == materialPara.UseFlag).ToList();
        }

        return result.Select(t => new MaterialBean
        {
            Id = t.Id,
            Spec = t.Spec,
            MaterialCode = t.MaterialCode,
            MaterialName = t.MaterialName,
            Inch = t.Inch,
            OutsideDiameter = t.OutsideDiameter,
            InsideDiameter = t.InsideDiameter,
            MaterialHeight = t.MaterialHeight,
            MaterialWeight = t.MaterialWeight,
            WeightLower = t.WeightLower,
            WeightUpper = t.WeightUpper,
            Unit = t.Unit,
            Useyn = t.Useyn,
            ExpirDuration = t.ExpirDuration / 60,
            InRation = t.Ration,
            CreateTime = t.CreateTime,
            UseFlag = t?.UseFlag == 1 ? true : false
        }).OrderByDescending(t => t.CreateTime).ToList();
    }
    [OperationLog("物料启用禁用")]
    public int UpdateMaterialUseFlag(MaterialExpirPara para, long userId, string userName, string clientHost)
    {
        var id = para.Id;

        var result = _ProdMaterial.UpdateMaterialUseFlagById(id);
        return result;
    }
    public int UpdateMaterialExpir(MaterialExpirPara materialExpirPara)
    {
        var id = materialExpirPara.Id;
        var expir = materialExpirPara.Expir * 60; // 转分钟
        var result = _ProdMaterial.UpdateMaterialById(id, expir);
        return result;
    }
    [OperationLog("修改物料比例")]
    public int UpdateMaterialCheck(MaterialCheckPara materialExpirPara, long userId, string userName, string clientHost)
    {

        var result = _ProdMaterial.UpdateMaterialCheckById(materialExpirPara.Id, materialExpirPara.Ration);
        return result;
    }

    [OperationLog("修改物料属性")]
    public int UpdateMaterialProperty(UpdateMaterialPropertyCondition condition, long userId, string userName, string clientHost)
    {
        var result = _ProdMaterial.UpdateMaterialPropertyById(condition);
        return result;
    }


    public int UpdateMaterialHeight(long id, decimal height)
    {
        var result = -1;

        if (height <= 0) { return result; }//胎高大于0

        var db = Db.Default;
        var material = db.ProdMaterials.Where(t => t.Id == id).FirstOrDefault();
        result = db.ProdMaterials.Where(t => t.Id == id)
        .Update( new POProdMaterial
        {
            MaterialHeight = height,//胎高
            ManualSign = 1//手工维护标志
        });
        return result;
    }
    public List<MaterialCuringInfo> GetMaterialCuringList(decimal num)
    {
        var result = _ProdMaterial.GetMaterialCuringList(num);
        return result;
    }
    public List<StockMaterialCount> GetStockMaterialCountList(StockMaterialCountPara parm)
    {
        var result = _ProdMaterial.GetStockMaterialCountList();
        if (!string.IsNullOrWhiteSpace(parm.materialCode))
        {
            result = result.Where(t => t.MaterialCode.Contains(parm.materialCode)).ToList();
        }
        return result;
    }
}
